﻿using IdentityModel.OidcClient;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WMS.ProductDetails;
using WMS.ProductDetails.Dto;

namespace WMS.Web.Controllers
{
	public class ProductDetailsController : Controller
	{
		private readonly IProductDetailsAppService _productDetailsAppService;

		public ProductDetailsController(IProductDetailsAppService productDetailsAppService)
		{
			_productDetailsAppService = productDetailsAppService;
		}

		public IActionResult ProductDetailsListView()
		{
			return View();
		}

		public IActionResult AddProductDetailsView()
		{
			return View();
		}

		public IActionResult UpdateProductDetailsView(int id)
		{
			ViewBag.id = id;
			return View();
		}

		[HttpGet]
		public async Task<JsonResult> GetProductDetailsList(int page, int limit,int belongsOwner)
		{
			var productDetailsList = await _productDetailsAppService.GetProductDetailsList(page, limit, belongsOwner);
			return Json(new { data = productDetailsList.Queryable, count = productDetailsList.RowCount, code = 0 });
		}

		[HttpPost]
		public async Task<int> AddProductDetails(ProductDetailsFiles.ProductDetails productDetailsModel)
		{
			int rowNum = await _productDetailsAppService.AddProductDetails(productDetailsModel);
			return rowNum;
		}


		[HttpGet]
		public async Task<int> RemoveProductDetails(int id)
		{
			int rowNum = await _productDetailsAppService.RemoveProductDetails(id);
			return rowNum;
		}

		[HttpGet]
		public async Task<ProductDetailsFiles.ProductDetails> FindProductDetails(int Id)
		{
			var productDetailsModel = await _productDetailsAppService.FindProductDetails(Id);
			return productDetailsModel;
		}

		[HttpPost]
		public async Task<int> UpdateProductDetails(UpdateProductDetails productDetailsModel)
		 {
			int rowNum = await _productDetailsAppService.UpdateProductDetails(productDetailsModel);
			return rowNum;
		}


		[HttpGet]
		public async Task<int> RemoveRangeProducctDetails(string ids)
		{
			//var entities = await _productDetailsRepository.GetAsync(ids);

			await _productDetailsAppService.RemoveRangeProducctDetails(ids);
			return 1;
		}


	}
}
